﻿<%@ Page Language="C#" MasterPageFile="~/MasterPages/Core.Master" AutoEventWireup="true"
    CodeBehind="LoanExecutionList.aspx.cs" Inherits="Pap.Web.Modules.Loan.Views.LoanExecutionList"
    meta:resourcekey="PageResource1" %>

<%@ Register Src="../../Shared/Views/InsertAttchments.ascx" TagName="InsertAttchments"
    TagPrefix="uc1" %>
<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <script type="text/javascript">
        function prepareToolbar(grid, toolbar, rowIndex, record) {
            // for example hide 'Edit' button if price < 50
            if (record.get("IsWaiting").toString() != "true") {
                //hide separator
                toolbar.items.itemAt(0).hide();
                toolbar.items.itemAt(1).hide();
            }
        }
    </script>
    <ext:Store runat="server" ID="storeBoards" AutoLoad="True" IDMode="Legacy">
        <Reader>
            <ext:JsonReader ReaderID="BoardID">
                <Fields>
                    <ext:RecordField Name="BoardID" />
                    <ext:RecordField Name="BoardNumber" />
                    <ext:RecordField Name="BoardDate" Type="Date" />
                    <ext:RecordField Name="PreviousNotes" />
                    <ext:RecordField Name="StatusNotes" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Store runat="server" ID="storeBoardLoans">
        <Reader>
            <ext:JsonReader ReaderID="LoanID">
                <Fields>
                    <ext:RecordField Name="LoanID" />
                    <ext:RecordField Name="CustomerName" />
                    <ext:RecordField Name="LoanNumber" />
                    <ext:RecordField Name="LoanCreatedDate" Type="Date" />
                    <ext:RecordField Name="CustomerName" />
                    <ext:RecordField Name="LoanType" />
                    <ext:RecordField Name="LoanAmount" />
                    <ext:RecordField Name="PaymentPeriod" />
                    <ext:RecordField Name="PaymentMethod" />
                    <ext:RecordField Name="PreviousNotes" />
                    <ext:RecordField Name="StatusNotes" />
                    <ext:RecordField Name="DecisionID" />
                    <ext:RecordField Name="IsWaiting" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Store runat="server" ID="storeLoanInstallments">
        <Reader>
            <ext:JsonReader>
                <Fields>
                    <ext:RecordField Name="InstallmentDate" />
                    <ext:RecordField Name="OriginalInstallmentAmount" />
                    <ext:RecordField Name="InterestInstallmentAmount" />
                    <ext:RecordField Name="TotalInstallmentAmount" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:FitLayout runat="server">
        <ext:Panel runat="server">
            <Body>
                <ext:RowLayout runat="server">
                    <ext:LayoutRow>
                        <ext:FormPanel runat="server" BodyStyle="padding:5px;" ButtonAlign="Right" AutoScroll="true">
                            <Body>
                                <ext:FormLayout runat="server" ID="frmLayoutErrors" ElementStyle="" ItemCls="" LabelWidth="100">
                                    <ext:Anchor>
                                        <ext:ComboBox FieldLabel="BoardType" runat="server" ID="cmbBoardTypes" meta:resourcekey="cmbBoardTypeResource"
                                            Editable="False" AllowBlank="False" TriggerAction="All" LabelStyle="text-align:left"
                                            Width="400">
                                            <Items>
                                                <ext:ListItem Text="<%$Resources:Executed %>" Value="Executed" />
                                                <ext:ListItem Text="<%$Resources:Approved %>" Value="Approved" />
                                                <ext:ListItem Text="<%$Resources:NotApproved %>" Value="NotApproved" />
                                            </Items>
                                            <AjaxEvents>
                                                <Select OnEvent="CmbBoardTypes_Selected">
                                                    <EventMask ShowMask="True" />
                                                </Select>
                                            </AjaxEvents>
                                        </ext:ComboBox>
                                    </ext:Anchor>
                                </ext:FormLayout>
                            </Body>
                        </ext:FormPanel>
                    </ext:LayoutRow>
                    <ext:LayoutRow RowHeight="1">
                        <ext:Panel runat="server">
                            <Body>
                                <ext:RowLayout runat="server">
                                    <ext:LayoutRow RowHeight="0.5">
                                        <ext:GridPanel runat="server" ID="grvBoards" StoreID="storeBoards" TrackMouseOver="True"
                                            Title="<%$ Resources:grvBoardsTitle %>" AutoScroll="true" AutoExpandColumn="StatusNotes"
                                            Frame="True" StripeRows="True">
                                            <ColumnModel>
                                                <Columns>
                                                    <ext:RowNumbererColumn />
                                                    <ext:Column DataIndex="BoardNumber" Header="<%$ Resources:grvHeaderBoardNumber %>"
                                                        Sortable="True" Width="60" Align="Center" />
                                                    <ext:Column DataIndex="BoardDate" Header="<%$ Resources:grvHeaderBoardDate %>" Sortable="True">
                                                        <Renderer Fn="Ext.util.Format.dateRenderer('d/m/Y')" />
                                                    </ext:Column>
                                                    <ext:Column DataIndex="PreviousNotes" Header="<%$ Resources:PreviousNotes %>" Sortable="false" />
                                                    <ext:Column DataIndex="StatusNotes" Header="<%$ Resources:grvHeaderStatusNotes %>"
                                                        Sortable="True">
                                                        <Editor>
                                                            <ext:TextArea ID="TextArea1" runat="server" />
                                                        </Editor>
                                                    </ext:Column>
                                                </Columns>
                                            </ColumnModel>
                                            <SelectionModel>
                                                <ext:RowSelectionModel ID="RowSelectionModel1" runat="server">
                                                    <AjaxEvents>
                                                        <SelectionChange OnEvent="Board_Selected" Before="#{grvBoardLoan}.body.mask('...', 'x-mask-loading');"
                                                            Success="#{grvBoardLoan}.body.unmask();" />
                                                    </AjaxEvents>
                                                </ext:RowSelectionModel>
                                            </SelectionModel>
                                        </ext:GridPanel>
                                    </ext:LayoutRow>
                                    <ext:LayoutRow RowHeight="0.5">
                                        <ext:GridPanel runat="server" ID="grvBoardLoan" StoreID="storeBoardLoans" Title="<%$ Resources:grvBoardLoansTitle %>"
                                            TrackMouseOver="True" StripeRows="true" Frame="True" AutoExpandColumn="StatusNotes">
                                            <Listeners>
                                                <BeforeEdit Handler="
					                        if(!e.record.data.IsWaiting) 
                                            {
						                        e.cancel=true;
                                                e.commands[0].disabled=true;
					                        }
				                        " />
                                            </Listeners>
                                            <ColumnModel>
                                                <Columns>
                                                    <ext:CheckColumn DataIndex="editable" Header="IsWaiting" Hidden="true" />
                                                    <ext:Column DataIndex="LoanNumber" Header="<%$ Resources:grvHeaderLoanNumber %>"
                                                        Sortable="True">
                                                    </ext:Column>
                                                    <ext:Column DataIndex="CustomerName" Header="<%$ Resources:grvHeaderCustomerName %>" />
                                                    <ext:Column DataIndex="LoanCreatedDate" Header="<%$ Resources:grvHeaderLoanCreatedDate %>"
                                                        Sortable="True">
                                                        <Renderer Fn="Ext.util.Format.dateRenderer('d/m/Y')" />
                                                    </ext:Column>
                                                    <ext:Column DataIndex="LoanType" Header="<%$ Resources:grvHeaderLoanType %>" Sortable="True" />
                                                    <ext:Column DataIndex="LoanAmount" Header="<%$ Resources:grvHeaderBoardLoanAmount %>"
                                                        Sortable="True" />
                                                    <ext:Column DataIndex="PaymentPeriod" Header="<%$ Resources:grvHeaderBoardPaymentPeriod %>"
                                                        Sortable="True" />
                                                    <ext:Column DataIndex="PaymentMethod" Header="<%$ Resources:grvHeaderBoardPaymentMethod %>"
                                                        Sortable="True" />
                                                    <ext:Column DataIndex="PreviousNotes" Header="<%$ Resources:PreviousNotes %>" Sortable="True" />
                                                    <ext:Column DataIndex="StatusNotes" Header="<%$ Resources:grvHeaderStatusNotes %>"
                                                        Sortable="True">
                                                        <Editor>
                                                            <ext:TextArea ID="TextArea2" runat="server" />
                                                        </Editor>
                                                    </ext:Column>
                                                    <ext:CommandColumn Align="Center" Header="<%$ Resources:grvHeaderDecision %>" Sortable="false"
                                                        Hideable="false" Hidden="false">
                                                        <Commands>
                                                            <ext:GridCommand CommandName="AcceptLoan" Icon="Accept">
                                                                <ToolTip Text="<%$ Resources:grvAccept %>" />
                                                            </ext:GridCommand>
                                                            <ext:GridCommand CommandName="RefuseLoan" Icon="Decline">
                                                                <ToolTip Text="<%$ Resources:grvRefuse %>" />
                                                            </ext:GridCommand>
                                                        </Commands>
                                                        <PrepareToolbar Fn="prepareToolbar" />
                                                    </ext:CommandColumn>
                                                </Columns>
                                            </ColumnModel>
                                            <AjaxEvents>
                                                <Command OnEvent="gvrLoans_Command">
                                                    <ExtraParams>
                                                        <ext:Parameter Name="CommandName" Value="command" Mode="Raw" Encode="False" />
                                                        <ext:Parameter Name="LoanID" Value="record.data.LoanID" Mode="Raw" Encode="False" />
                                                        <ext:Parameter Name="grvBoardLoan" Value="Ext.encode(#{grvBoardLoan}.getRowsValues(true))"
                                                            Mode="Raw" />
                                                    </ExtraParams>
                                                    <EventMask ShowMask="true" Msg="..." />
                                                    <Confirmation BeforeConfirm="return (command == 'RefuseLoan');" ConfirmRequest="true"
                                                        Message="<%$Resources:ConfirmRefuse %>" Title="<%$Resources:Confirm %>" />
                                                </Command>
                                            </AjaxEvents>
                                            <SelectionModel>
                                                <ext:RowSelectionModel ID="RowSelectionModel2" runat="server" />
                                            </SelectionModel>
                                        </ext:GridPanel>
                                    </ext:LayoutRow>
                                </ext:RowLayout>
                            </Body>
                        </ext:Panel>
                    </ext:LayoutRow>
                </ext:RowLayout>
            </Body>
            <BottomBar>
                <ext:StatusBar ID="statusBar" runat="server">
                    <Items>
                        <ext:Button runat="server" IDMode="Static" ID="btnBack" Text="<%$ Resources:BackButton %>"
                            Icon="ArrowUndo">
                            <AjaxEvents>
                                <Click OnEvent="btnBack_Clicked" />
                            </AjaxEvents>
                        </ext:Button>
                    </Items>
                </ext:StatusBar>
            </BottomBar>
        </ext:Panel>
    </ext:FitLayout>
    <ext:Window runat="server" ID="wndLoan" Modal="true" ShowOnLoad="false" Closable="false" Frame="true"
        AutoHeight="true" Width="600px" Title="<%$ Resources:wndTitle %>" Collapsible="false"
        CloseAction="Close" AutoScroll="true">
        <Body>
            <ext:Hidden ID="txtLoanID" runat="server" />
            <ext:FormPanel ID="pnlLoan" runat="server" Frame="true">
                <Body>
                    <ext:FormLayout runat="server">
                        <ext:Anchor Horizontal="95%">
                            <ext:MultiField runat="server" FieldLabel="<%$ Resources:ExecutionDate %>">
                                <Fields>
                                    <ext:DateField ID="dtExecutionDate" runat="server" Disabled="true" Format="dd-MM-yyyy"
                                        HideLabel="true" meta:resourcekey="dtExecutionDateResource1" />
                                    <ext:Button ID="btnOldDate" runat="server" Text="<%$ Resources:btnOldDate %>">
                                        <AjaxEvents>
                                            <Click OnEvent="btnOldDate_Click">
                                                <Confirmation ConfirmRequest="true" BeforeConfirm="return !#{dtExecutionDate}.disabled;"
                                                    Message="<%$ Resources:ConfirmOldDate %>" Title="<%$Resources:Confirm %>" />
                                            </Click>
                                        </AjaxEvents>
                                    </ext:Button>
                                </Fields>
                            </ext:MultiField>
                        </ext:Anchor>
                        <ext:Anchor Horizontal="95%">
                            <ext:TextField runat="server" ID="txtCheckNumber" MaxLength="20" AllowBlank="false"
                                meta:resourcekey="txtCheckNumberResource1" Regex="^[0-9A-zء-ي' ']+$" />
                        </ext:Anchor>
                        <ext:Anchor Horizontal="95%">
                            <ext:DateField runat="server" ID="dtCheckDate" AllowBlank="false" meta:resourcekey="dtCheckDateResource1" />
                        </ext:Anchor>
                        <ext:Anchor Horizontal="95%">
                            <ext:TextField ID="txtGuarantor" runat="server" AllowBlank="false" Regex="^[A-zء-ي' ']+$"
                                MaxLength="50" meta:resourcekey="txtGurantorNameResource1" />
                        </ext:Anchor>
                        <ext:Anchor Horizontal="95%">
                            <ext:NumberField ID="txtGuarantorSSN" runat="server" AllowBlank="false" MaxLength="14"
                                MinLength="14" meta:resourcekey="txtGurantorSSNResource1">
                                <AjaxEvents>
                                    <Change OnEvent="txtSSID_Changed" />
                                </AjaxEvents>
                            </ext:NumberField>
                        </ext:Anchor>
                        <ext:Anchor>
                            <ext:Panel runat="server" ID="panelGuarantorErrors">
                                <Body>
                                    <ext:Panel runat="server" ID="panelHasOpenLoan" Hidden="true">
                                        <Body>
                                            <ext:Label ID="Label1" runat="server" Icon="Error" Text="<%$ Resources:GuarntorHasOpenLoan%>" />
                                        </Body>
                                    </ext:Panel>
                                    <ext:Panel runat="server" ID="panelGuarantorError" Hidden="true">
                                        <Body>
                                            <ext:Label ID="Label2" runat="server" Icon="Error" Text="<%$ Resources:GuarntorWarningText%>" />
                                        </Body>
                                    </ext:Panel>
                                    <ext:Panel runat="server" ID="panelProcecuted" Hidden="true">
                                        <Body>
                                            <ext:Label ID="Label3" runat="server" Icon="Error" Text="<%$ Resources:GuarntorProcecuted%>" />
                                        </Body>
                                    </ext:Panel>
                                </Body>
                            </ext:Panel>
                        </ext:Anchor>
                        <ext:Anchor Horizontal="95%">
                            <ext:TextArea ID="txtNotes" runat="server" FieldLabel="<%$ Resources:Notes %>" AllowBlank="true"
                                MaxLength="250" />
                        </ext:Anchor>
                        <ext:Anchor>
                            <ext:MultiField runat="server" HideLabel="true">
                                <Fields>
                                    <ext:Button runat="server" ID="btnShowInstallments" Text="<%$ Resources:btnInstallments %>" Flat="true" Icon="MoneyPound">
                                        <AjaxEvents>
                                            <Click OnEvent="btnShowInstallments_Click" Before="return #{pnlLoan}.getForm().isValid();" />
                                        </AjaxEvents>
                                    </ext:Button>
                                    <ext:Button runat="server" ID="btnShowContract" Text="<%$ Resources:btnContract %>" Flat="true" Icon="Book">
                                        <AjaxEvents>
                                            <Click OnEvent="btnShowContract_Click" Before="return #{pnlLoan}.getForm().isValid();" />
                                        </AjaxEvents>
                                    </ext:Button>
                                </Fields>
                            </ext:MultiField>
                        </ext:Anchor>
                       <ext:Anchor Horizontal="100%">
                            <ext:Panel runat="server" Title="Attachments" Collapsible="true">
                                <Body>
                                    <uc1:InsertAttchments runat="server" ViewMode="Edit" ID="ucAttachment" />
                                </Body>
                            </ext:Panel>
                        </ext:Anchor>
                    </ext:FormLayout>
                </Body>
            </ext:FormPanel>
        </Body>
        <BottomBar>
            <ext:StatusBar runat="server" meta:resourcekey="FormStatusBarResource1">
                <Items>
                    <ext:Button runat="server" ID="btnCancle" Icon="ArrowUndo" meta:resourcekey="btnCancleResource1">
                        <AjaxEvents>
                            <Click OnEvent="BtnCancle_Clicked" />
                        </AjaxEvents>
                    </ext:Button>
                    <ext:Button runat="server" ID="btnSave" Icon="Disk" meta:resourcekey="btnSaveResource1">
                        <AjaxEvents>
                            <Click OnEvent="BtnSave_Clicked" Before="return #{pnlLoan}.getForm().isValid();">
                                <Confirmation ConfirmRequest="true" BeforeConfirm="return #{pnlLoan}.getForm().isValid();"
                                    Message="<%$ Resources:ConfirmSave %>" Title="<%$Resources:Confirm %>" />
                            </Click>
                        </AjaxEvents>
                    </ext:Button>
                    <ext:Button runat="server" ID="btnSubmit" Icon="Accept" meta:resourcekey="btnSubmitResource1">
                        <AjaxEvents>
                            <Click OnEvent="BtnSubmit_Clicked" Before="return #{pnlLoan}.getForm().isValid();">
                                <Confirmation ConfirmRequest="true" BeforeConfirm="return #{pnlLoan}.getForm().isValid();"
                                    Message="<%$ Resources:ConfirmSubmit %>" Title="<%$Resources:Confirm %>" />
                            </Click>
                        </AjaxEvents>
                    </ext:Button>
                </Items>
                <Plugins>
                    <ext:ValidationStatus ID="wndpnlValidation" FormPanelID="pnlLoan" ValidIcon="Accept"
                        ErrorIcon="Exclamation" runat="server" meta:resourcekey="wndpnlValidationResource1" />
                </Plugins>
            </ext:StatusBar>
        </BottomBar>
    </ext:Window>
    <ext:Window runat="server" ID="wndInstallmentPrint" Modal="true" ShowOnLoad="false"
        Width="550px" Height="480px">
        <AutoLoad Mode="IFrame" ShowMask="True" ManuallyTriggered="True" PassParentSize="True" />
        <AjaxEvents>
            <Close OnEvent="wndInstallmentPrint_Closed" />
        </AjaxEvents>
    </ext:Window>
</asp:Content>
